package com.zhanqiao.controller;


import com.google.gson.Gson;
import com.zhanqiao.domain.ArticleBean;
import com.zhanqiao.domain.ResponseBean;
import com.zhanqiao.service.DraftService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/getdrafts.action")
public class ArticleController  extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        DraftService draftService = new DraftService();
        List<ArticleBean> drafts = draftService.articleService(page,limit);
//        System.out.println(articleBean);
        resp.setContentType("application/json;charset=utf-8");
        if(drafts==null){
            resp.getWriter().write("数据未找到");
        }else{
            ResponseBean responseBean =new ResponseBean();
            responseBean.setCode(0);
            responseBean.setMsg("myms");
            responseBean.setCount(1000);
            responseBean.setData(drafts);
            String result = new Gson().toJson(responseBean);
            resp.getWriter().write(result);
//            resp.getWriter().write();
        }

    }
}
